package top.superflow.db.orientdb

import javax.annotation.PostConstruct
import org.springframework.context.annotation.Bean
import org.springframework.data.orient.`object`.{OrientObjectDatabaseFactory, OrientObjectTemplate}
import org.springframework.data.orient.commons.core.OrientTransactionManager
import org.springframework.data.orient.commons.repository.config.EnableOrientRepositories
import org.springframework.transaction.annotation.EnableTransactionManagement

@EnableTransactionManagement
@EnableOrientRepositories(basePackages =  Array("top.superflow.flow.config"))
class OrientDBSpringConfig {




  @Bean def factory: OrientObjectDatabaseFactory = {
    val factory = new OrientObjectDatabaseFactory
    factory.setUrl("remote:127.0.0.1/Superflow")
    factory.setUsername("superflow")
    factory.setPassword("superflow")
    factory
  }

  @Bean def transactionManager = new OrientTransactionManager(factory)

  @Bean def objectTemplate = new OrientObjectTemplate(factory)


  @PostConstruct def registerEntities(): Unit = {
    factory.db.getEntityManager.registerEntityClass(classOf[Nothing])
  }
}
